import type { IFieldProps, IConfigProps } from '@/components/sofastui/AdvancedTable/interface'
import type { FormRule } from '@form-create/element-ui'

export const fields: IFieldProps[] = [
  {
    label: 'ID',
    prop: 'id',
    width: 60,
    align: 'center',
    import: false,
    export: true,
    select: false,
    sort: true,
  },
  {
    label: '用户名',
    prop: 'username',
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '姓名',
    prop: 'nickname',
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '手机号',
    prop: 'phone',
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '邮箱',
    prop: 'email',
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '所属组织',
    prop: 'org.name',
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '用户类型',
    prop: 'userType.name',
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '角色',
    prop: 'roles',
    slot: true,
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '岗位',
    prop: 'jobs',
    slot: true,
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '性别',
    prop: 'sex',
    width: 100,
    align: 'center',
    import: true,
    export: true,
    type: 'radio',
    isTag: true,
    filter: true,
    options: [
      {
        label: '男性',
        value: 1,
      },
      {
        label: '女性',
        value: 2,
      },
      {
        label: '不公开',
        value: 0,
      },
    ],
  },
  {
    label: '状态',
    prop: 'enabled',
    width: 80,
    align: 'center',
    import: true,
    export: true,
    type: 'switch',
    isTag: true,
    filter: true,
    options: [
      {
        label: '启用',
        value: 1,
      },
      {
        label: '停用',
        value: 0,
      },
      {
        label: '锁定',
        value: 2,
      },
    ],
  },
  {
    label: '创建时间',
    prop: 'createdAt',
    width: 180,
    import: true,
    export: true,
    sort: true,
  },
]

export const config: IConfigProps = {
  name: 'powUserTable',
  rowKey: 'id',
  url: '/api/idt/user',
  selection: true,
  add: true,
  delete: true,
  expand: true,
  showIndex: true,
  import: true,
  export: true,
  search: true,
  advancedSearch: true,
  refresh: true,
  settings: true,
}

export const formRules: FormRule = [
  {
    type: 'select',
    field: 'userTypeId',
    title: '用户类型',
    effect: {
      fetch: {
        parse:
          '[[FORM-CREATE-PREFIX-function (res, rule, api){\nif(res.code === 200) return res.data.map(i=>({label:i.name,value:i.id}));\nreturn [];\n}-FORM-CREATE-SUFFIX]]',
        beforeFetch: '',
        onError: '',
        to: 'options',
        action: '/api/idt/user_type',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
      },
    },
    $required: true,
    props: {
      _optionType: 3,
      clearable: true,
    },
    _fc_id: 'id_Fwh5mc35zbnbchc',
    name: 'userTypeId',
    display: true,
    hidden: false,
    _fc_drag_tag: 'select',
    col: {
      span: 12,
    },
  },
  {
    type: 'elTreeSelect',
    field: 'orgId',
    title: '所属组织',
    effect: {
      fetch: {
        parse:
          '[[FORM-CREATE-PREFIX-function (res, rule, api){\nif(res.code === 200) return res.data;\nreturn [];\n}-FORM-CREATE-SUFFIX]]',
        beforeFetch: '',
        onError: '',
        to: 'props.data',
        action: '/api/idt/org/tree',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
      },
    },
    $required: false,
    props: {
      nodeKey: 'id',
      showCheckbox: false,
      _optionType: 3,
      expandOnClickNode: false,
      props: {
        label: 'name',
      },
      checkStrictly: true,
    },
    _fc_id: 'id_Frq7mc97xi4nahc',
    name: 'orgId',
    display: true,
    hidden: false,
    _fc_drag_tag: 'elTreeSelect',
    col: {
      span: 12,
    },
  },
  {
    type: 'select',
    field: 'roleIds',
    title: '用户角色',
    effect: {
      fetch: {
        parse:
          '[[FORM-CREATE-PREFIX-function (res, rule, api){\nif(res.code === 200) return res.data.map(i=>({label:i.name,value:i.id}));\nreturn [];\n}-FORM-CREATE-SUFFIX]]',
        beforeFetch: '',
        onError: '',
        to: 'options',
        action: '/api/idt/role',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
      },
    },
    $required: false,
    props: {
      _optionType: 3,
      clearable: true,
      multiple: true,
    },
    _fc_id: 'id_Fwh5mc45zbnbchc',
    name: 'roleIds',
    display: true,
    hidden: false,
    _fc_drag_tag: 'select',
    col: {
      span: 12,
    },
  },
  {
    type: 'select',
    field: 'jobIds',
    title: '用户岗位',
    effect: {
      fetch: {
        parse:
          '[[FORM-CREATE-PREFIX-function (res, rule, api){\nif(res.code === 200) return res.data.map(i=>({label:i.name,value:i.id}));\nreturn [];\n}-FORM-CREATE-SUFFIX]]',
        beforeFetch: '',
        onError: '',
        to: 'options',
        action: '/api/idt/job',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
      },
    },
    $required: false,
    props: {
      _optionType: 3,
      clearable: true,
      multiple: true,
    },
    _fc_id: 'id_Fwh5mc55zbnbchc',
    name: 'jobIds',
    display: true,
    hidden: false,
    _fc_drag_tag: 'select',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'username',
    title: '用户名',
    $required: true,
    props: {
      placeholder: '请输入用户名',
    },
    _fc_id: 'id_F2abmc34zpa2bnc',
    name: 'username',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'pswd',
    title: '密码',
    $required: false,
    props: {
      type: 'password',
      placeholder: '请输入密码',
    },
    _fc_id: 'id_Fscqmc3516c5btc',
    name: 'pswd',
    display: true,
    hidden: false,
    _fc_drag_tag: 'password',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'nickname',
    title: '用户昵称',
    $required: false,
    props: {
      placeholder: '请输入用户昵称',
    },
    _fc_id: 'id_F155mc35joi0c5c',
    name: 'nickname',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'idcard',
    title: '身份证号码',
    $required: false,
    props: {
      placeholder: '请输入身份证号码',
    },
    _fc_id: 'id_F1o2mc35ikopc2c',
    name: 'idcard',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'phone',
    title: '手机号码',
    $required: false,
    props: {
      placeholder: '请输入手机号码',
    },
    _fc_id: 'id_Fut5mc352boibwc',
    name: 'phone',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'email',
    title: '邮箱地址',
    $required: false,
    props: {
      placeholder: '请输入邮箱地址',
    },
    _fc_id: 'id_F2mqmc354me1bzc',
    name: 'email',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'radio',
    field: 'sex',
    title: '性别',
    effect: {
      fetch: '',
    },
    $required: false,
    value: 0,
    options: [
      {
        label: '男性',
        value: 1,
      },
      {
        label: '女性',
        value: 2,
      },
      {
        label: '不公开',
        value: 0,
      },
    ],
    _fc_id: 'id_Ft90mc35kyt4c8c',
    name: 'sex',
    display: true,
    hidden: false,
    _fc_drag_tag: 'radio',
    col: {
      span: 12,
    },
  },
  {
    type: 'radio',
    field: 'enabled',
    title: '禁用状态',
    info: '禁用状态下不可登录',
    effect: {
      fetch: '',
    },
    $required: false,
    value: 1,
    options: [
      {
        label: '禁用',
        value: 0,
      },
      {
        label: '启用',
        value: 1,
      },
    ],
    _fc_id: 'id_F50kmc35nzrccbc',
    name: 'enabled',
    display: true,
    hidden: false,
    _fc_drag_tag: 'radio',
    col: {
      span: 12,
    },
  },
]
